<?php
/**
 ***********************************************************************************************************************
 * 微快递账号服务
 ***********************************************************************************************************************
 */
namespace soa\account;

use soa\client;

/**
 * Class user
 */
class user extends client
{
    /**
     * 服务地址
     * @var string
     */
    public $service_url = 'http://account.core.kuaidihelp.com/';

    /**
     * 服务名称
     * @var string
     */
    protected $service_name = 'kuaidihelp_account';

    /**
     * 根据用户id获取微快递用户信息
     * @param $courier_id
     * @return array
     */
    public function getUserById($user_id)
    {
        if (empty($user_id) || !is_numeric($user_id)) {
            return [];
        }
        return $this->get('v1/user/info', ['user_id' => $user_id]);
    }

    /**
     * 根据用户名码获取微快递用户信息
     * @param $mobile
     * @return bool|null
     */
    public function getUserByName($username)
    {
        if (empty($username) /*|| !is_numeric($username) || strlen($username) != 11*/) {
            return array();
        }

        return  $this->get('v1/user/info', array('username' => $username));


    }

    /**
     * 根据用户名和密码登录
     * @param $username
     * @param $password
     * @param $ip
     * @param $channel
     */
    public function signin($username, $password , $ip = '' , $channel = 'www')
    {
        if (empty($username) || empty($password)) {
            return array();
        }

        return $this->get('v1/user/signin/index', array('username' => $username, 'password' => $password,'ip'=>$ip,'channel'=>$channel));
    }

    /**
     * 用户注册
     * @param $username
     * @param $password
     * @param $smscode
     * @param $realname
     */
    public function signup($username, $password, $smscode, $realname, $from_channel = '')
    {
        if (empty($username)) {
            return array();
        }
        $gdata = array('username' => $username, 'password' => $password, 'smscode' => $smscode, 'realname' => $realname, 'from_channel' => $from_channel);
        return $this->get('v1/user/signup/index', $gdata);
    }
	public function signup_weixin($username){
		if (empty($username)) {
            return array();
        }
        $gdata = array('username' => $username);
        return $this->get('v1/user/signup/wx_code', $gdata);
	}

    public function signup_alipayfuwuchuang($username){
        if (empty($username)) {
            return array();
        }
        $data = array('username' => $username);

        return $this->get('v1/user/signup/alipayfuwuchuang_code',$data);
    }

    /**
     * 用户注册
     * @param $username
     * @param $password
     * @param $smscode
     * @param $realname
     */
    public function reset($username, $password, $smscode)
    {
        if (empty($username)) {
            return array();
        }
        $gdata = array('username' => $username, 'password' => $password, 'smscode' => $smscode);
        return $this->get('v1/user/reset/index', $gdata);
    }

    /**
     * 更新用户资料
     * @param $user_id
     * @param $data
     */
    public function update($user_id, $data)
    {
        if (empty($user_id) || empty($data)) {
            return array();
        }
        $data['user_id'] = $user_id;
        return $this->get('v1/user/update/index', $data);
    }

    /**
     * 根据第三方帐号登录
     * @param $openid
     * @param $type
     */
    public function thirdSignin($openid, $type)
    {
        if (empty($openid) || empty($type)) {
            return array();
        }

        $result = $this->get('v1/user/third/signin', array('openid' => $openid, 'type' => $type));
        return $result;
    }

    /**
     * 添加第三方认证关联信息
     */
    public function addThird($userid, $openid, $type)
    {
        if (empty($userid) || empty($openid) || empty($type)) {
            return array();
        }

        return $this->get('v1/user/third/add', array('userid' => $userid, 'openid' => $openid, 'type' => $type));
    }

    /**
     * 判断用户是否绑定第三方登录
     * @param $userid
     * @param $type
     * @return array|bool
     */
    public function isBindThird($userid, $type){
        if (empty($userid)) {
            return array();
        }

        return $this->get('v1/user/third/is_bind_third', array('userid' => $userid,'type' => $type));
    }

    /**
     * 添加用户
     * @param $username
     * @param $password
     */
    public function addUser($data)
    {

        if (empty($data)) {
            return array();
        }

        return $this->get('v1/user/add/index', $data);
    }

    /**
     * 根据user_id 获取登录session信息
     * @param $user_id
     * @return array
     */
    public function getSessionByUserid($user_id)
    {
        if (empty($user_id)) {
            return array();
        }
        return $this->get('v1/user/session/index', array('user_id' => $user_id));
    }

    /**
     * 根据session_id 获取用户信息
     * @param $session_id
     * @return array
     */
    public function getUserBySessionId($session_id)
    {
        if (empty($session_id)) {
            return array();
        }
        return $this->get('v1/user/session/info', array('session_id' => $session_id));
    }

    /**
     * 根据user_id和refresh_session重新获取session信息
     * @param $user_id
     * @param $refresh_session
     * @return array
     */
    public function refreshSession($user_id, $refresh_session)
    {
        if (empty($user_id) || empty($refresh_session)) {
            return array();
        }
        return $this->get('v1/user/session/refresh', array('user_id' => $user_id, 'refresh_session' => $refresh_session));
    }

    /**
     * 发送绑定短信
     * @param $username
     * @return bool
     */
    public function sendBindSms($username)
    {
        return $this->get('v1/user/third/sendSms', array('username' => $username));
    }

    /**
     * 验证短信
     * @param $username
     * @return bool
     */
    public function verifyBindSms($username, $smscode)
    {
        return $this->get('v1/user/third/verify', array('username' => $username, 'smsCode' => $smscode));
    }


    /**
     * 微信小程序绑定
     * @param $userInfo
     * @return array|bool|null
     */
    public function signUser($userInfo){

        if (empty($userInfo)) {
            return [];
        }
        return $this->get('v1/user/MiniApp/signUser', ['userInfo' => $userInfo]);
    }

    /**
     * 微商小程序绑定
     * @param $userInfo
     * @return array|bool|null
     */
    public function signWsUser($userInfo){

        if (empty($userInfo)) {
            return [];
        }
        return $this->get('v1/user/WsApp/signUser', ['userInfo' => $userInfo]);
    }
    /**
     * 修改微商与快递员协议信息
     * @param $userInfo
     * @return array|bool|null
     */
    public function upWsUser($where,$data){

        if (empty($where) && empty($data)) {
            return [];
        }
        return $this->get('v1/user/WsApp/upWsUser', ['where' => $where,'data'=>$data]);
    }
    /**
     * 修改微商与下线协议信息
     * @param $userInfo
     * @return array|bool|null
     */
    public function wsRelieve($where,$data){

        if (empty($where) && empty($data)) {
            return [];
        }
        return $this->get('v1/user/WsApp/wsRelieve', ['where' => $where,'data'=>$data]);
    }
    /**
     * 修改微商用户信息
     * @param $userInfo
     * @return array|bool|null
     */
    public function upUserInfo($where,$data){

        if (empty($where) && empty($data)) {
            return [];
        }
        return $this->get('v1/user/WsApp/upUserInfo', ['where' => $where,'data'=>$data]);
    }
    /**
     * 查询微商用户信息
     * @param $userId
     * @return array|bool|null
     */
    public function getWsUserInfo($userId){

        if (empty($userId)) {
            return [];
        }
        return $this->get('v1/user/WsApp/getWsUserInfo', ['userId' => $userId]);
    }

    /**
     * 小程序绑定电话号码
     * @param $data
     * @return array|bool|null
     */
    public function bindUserMobile($data)
    {
        if (empty($data)) {
            return [];
        }
        return $this->get('v1/user/MiniApp/bindUserMobile', $data);
    }
    /**
     * 获取微商关系列表
    **/
    public function getProtocolList($where){
        if (empty($where)) {
            return [];
        }
        return $this->get('v1/user/WsApp/getProtocolList', array("where"=>$where));
    }

    /**
     * 获取我的团队列表
     **/
    public function getMyTeamList($where){
        if (empty($where)) {
            return [];
        }
        return $this->get('v1/user/WsApp/getMyTeamList', array("where"=>$where));
    }
    /**
     * 获取我的团队列表
     **/
    public function getMyMerchantList($where,$page,$limit){
        if (empty($where)) {
            return [];
        }
        return $this->get('v1/user/WsApp/getMyMerchantList', array("where"=>$where,"page"=>$page,"limit"=>$limit));
    }
}